# websocket_utils.py - WebSocket工具类
import logging

logger = logging.getLogger(__name__)

def test_websocket():
    """测试WebSocket可用性"""
    try:
        import websocket
        logger.info("WebSocket模块可用")
        return True
    except ImportError:
        logger.warning("WebSocket模块不可用")
        return False

def get_websocket_app():
    """获取WebSocketApp类"""
    try:
        import websocket
        return websocket.WebSocketApp
    except ImportError:
        logger.error("无法导入WebSocketApp")
        return None

def create_websocket_connection(url, timeout=30):
    """创建WebSocket连接"""
    try:
        import websocket
        return websocket.create_connection(url, timeout=timeout)
    except ImportError:
        logger.error("无法创建WebSocket连接")
        return None
    except Exception as e:
        logger.error(f"WebSocket连接失败: {e}")
        return None